package org.dromara.tearoom.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.tearoom.domain.vo.TerHornEquipmentVo;
import org.dromara.tearoom.domain.bo.TerHornEquipmentBo;
import org.dromara.tearoom.service.ITerHornEquipmentService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 喇叭设备管理
 * 前端访问路由地址为:/tearoom/hornEquipment
 *
 * @author xch
 * @date 2025-04-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hornEquipment")
public class TerHornEquipmentController extends BaseController {

    private final ITerHornEquipmentService terHornEquipmentService;

    /**
     * 查询喇叭设备管理列表
     */
    @SaCheckPermission("tearoom:hornEquipment:list")
    @GetMapping("/list")
    public TableDataInfo<TerHornEquipmentVo> list(TerHornEquipmentBo bo, PageQuery pageQuery) {
        return terHornEquipmentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出喇叭设备管理列表
     */
    @SaCheckPermission("tearoom:hornEquipment:export")
    @Log(title = "喇叭设备管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TerHornEquipmentBo bo, HttpServletResponse response) {
        List<TerHornEquipmentVo> list = terHornEquipmentService.queryList(bo);
        ExcelUtil.exportExcel(list, "喇叭设备管理", TerHornEquipmentVo.class, response);
    }

    @SaCheckPermission("tearoom:hornEquipment:add")
    @Log(title = "喇叭设备立即播报", businessType = BusinessType.INSERT)
    @PostMapping("/idlyBroadcast")
    public  R<Void>  idlyBroadcast(@Validated(AddGroup.class) @RequestBody  TerHornEquipmentBo bo){
        return toAjax(terHornEquipmentService.idlyBroadcast(bo,null));
    }
    /**
     * 获取喇叭设备管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("tearoom:hornEquipment:query")
    @GetMapping("/{id}")
    public R<TerHornEquipmentVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(terHornEquipmentService.queryById(id));
    }

    /**
     * 新增喇叭设备管理
     */
    @SaCheckPermission("tearoom:hornEquipment:add")
    @Log(title = "喇叭设备管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TerHornEquipmentBo bo) {
        return toAjax(terHornEquipmentService.insertByBo(bo));
    }

    /**
     * 修改喇叭设备管理
     */
    @SaCheckPermission("tearoom:hornEquipment:edit")
    @Log(title = "喇叭设备管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TerHornEquipmentBo bo) {
        return toAjax(terHornEquipmentService.updateByBo(bo));
    }

    /**
     * 删除喇叭设备管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("tearoom:hornEquipment:remove")
    @Log(title = "喇叭设备管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("ids") Long[] ids) {
        return toAjax(terHornEquipmentService.deleteWithValidByIds(List.of(ids), true));
    }
}
